<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>格式化 GMT/UTC 日期／时间</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.gettimeofday.html">« gettimeofday</a></li>
      <li style="float: right;"><a href="function.gmmktime.html">gmmktime »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.datetime.html">Date/Time 函数</a></li>
    <li>格式化 GMT/UTC 日期／时间</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.gmdate" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">gmdate</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">gmdate</span> &mdash; <span class="dc-title">格式化 GMT/UTC 日期／时间</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.gmdate-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>gmdate</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$format</code></span>, <span class="methodparam"><span class="type">?</span><span class="type"><span class="type">int</span><span class="type"></span></span> <code class="parameter">$timestamp</code><span class="initializer"> = <strong><code>null</code></strong></span></span>): <span class="type">string</span></div>

  <p class="para rdfs-comment">
   同 <span class="function"><a href="function.date.html" class="function">date()</a></span> 函数一样，只是返回的时间是格林威治标准时（GMT）。
  </p>
 </div>
 

 <div class="refsect1 parameters" id="refsect1-function.gmdate-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">format</code></dt>

     <dd>

      <p class="para">
       输出日期 <span class="type">string</span> 的格式。参阅 <span class="function"><a href="function.date.html" class="function">date()</a></span> 函数格式化选项。
      </p>
     </dd>

    
    
    <dt>
<code class="parameter">timestamp</code></dt>
<dd>
<p class="para">
可选的 <code class="parameter">timestamp</code> 参数是一个 <span class="type">int</span> 的 Unix
时间戳，如未指定或是 <strong><code>null</code></strong>，参数值默认为当前本地时间。也就是说，其值默认为
<span class="function"><a href="function.time.html" class="function">time()</a></span> 的返回值。</p></dd>

   
   </dl>

  </p>
 </div>
   

 <div class="refsect1 returnvalues" id="refsect1-function.gmdate-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回格式化的日期字符串。
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.gmdate-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>8.0.0</td>
       <td>
        现在 <code class="parameter">timestamp</code> 允许为 null。
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.gmdate-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2096">
    <p><strong>示例 #1 <span class="function"><strong>gmdate()</strong></span> 示例</strong></p>
    <div class="example-contents"><p>
     在芬兰（GMT +0200）运行时，下面的第一行打印“Jan 01
     1998 00:00:00”，第二行打印“Dec 31 1997 22:00:00”。
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">date</span><span style="color: #007700">(</span><span style="color: #DD0000">"M&nbsp;d&nbsp;Y&nbsp;H:i:s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1998</span><span style="color: #007700">));<br />echo&nbsp;</span><span style="color: #0000BB">gmdate</span><span style="color: #007700">(</span><span style="color: #DD0000">"M&nbsp;d&nbsp;Y&nbsp;H:i:s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mktime</span><span style="color: #007700">(</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1998</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.gmdate-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="datetimeimmutable.construct.html" class="methodname" rel="rdfs-seeAlso">DateTimeImmutable::__construct()</a> - Returns new DateTimeImmutable object</span></li>
    <li class="member"><span class="methodname"><a href="datetime.format.html" class="methodname" rel="rdfs-seeAlso">DateTimeInterface::format()</a> - 按照指定格式返回格式化后的日期</span></li>
    <li class="member"><span class="function"><a href="function.date.html" class="function" rel="rdfs-seeAlso">date()</a> - 格式化 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.mktime.html" class="function" rel="rdfs-seeAlso">mktime()</a> - 取得一个日期的 Unix 时间戳</span></li>
    <li class="member"><span class="function"><a href="function.gmmktime.html" class="function" rel="rdfs-seeAlso">gmmktime()</a> - 取得 GMT 日期的 UNIX 时间戳</span></li>
    <li class="member"><span class="methodname"><a href="intldateformatter.format.html" class="methodname" rel="rdfs-seeAlso">IntlDateFormatter::format()</a> - Format the date/time value as a string</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>